//==========================================================================
// Copyright (c) 2000-2006,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __FRAMEBUFFER_H__
#define __FRAMEBUFFER_H__

#include <display.h>
typedef void (*BufferCopyFunc)(void);

#define UNTRANSRGBFBPIXELBYTES   3

typedef struct {
    Int32 Width;
    Int32 Height;
    Int32 PosX;
    Int32 PosY;
//    WORD *OverlapFb;
}overlapFormat;


typedef struct {
    Int32 nMobileWidth;
    Int32 nMobileHeight;

    Int32 nLCDPosX;
    Int32 nLCDPosY;

    Int32 nLCDWidth;
    Int32 nLCDHeight;
    Int32 nLCDColorBits;
    Int32 nTransparencyKey;

    // Usually bLCDTransSupport == bOverlay2Support
    Boolean bIsOverlap;//When overlay is setted, there must overlay1 or overlay2 be setted
    Boolean bIsSetOverlay1;//When bIsSetOverlay1 is TURE, bIsOverlay must be TURE
    Boolean bIsSetOverlay2;//When bIsSetOverlay2 is TURE, bIsOverlay must be TURE
    Boolean bIsUnderlay;//TURE : Underlay

    Boolean bShowLCDOnly;

    ColorFormat BasePlaneColorFormat;
    Int32 nBasePlanePixelBits;
    Int32 nBasePlanePixelBytes;
    void *pBasePlaneFb; // framebuffer address of base plane
    UInt32 nBasePlaneSize; // framebuffer size (bytes)

    OverlayFormat overlay1;
    Int32 nOverlay1PixelBytes;
    void *pOverlay1Fb; // framebuffer address of Overlay1 plane
    UInt32 nOverlay1Size; // framebuffer size (bytes)

    OverlayFormat overlay2;
    void *pOverlay2Fb; // framebuffer address of YCbCr Overlay2
    UInt32 nOverlay2Size; // framebuffer size (bytes)

    Byte *pTransArray; //Transparence Array used to record the baseplane transparence bits
    UInt32 nTransArraySize; // Transparence Array size

    overlapFormat overlapArea;//The Area is overlaped by three layer

    BufferCopyFunc pBaseplaneBufferCopy;
    BufferCopyFunc pOverlay2BufferCopy;
    BufferCopyFunc pOverlay1BufferCopy;
    BufferCopyFunc OverlapAreaOperation;//Some special operation of the Overlap area

    Boolean bRender;
    Boolean bAutoRender;
} VideoContext;

EXTERN_C void * Video_InitBasePlaneFramebuffer();
EXTERN_C Boolean Video_SetOverlay(OverlayFormat *pOverlayFormat);
EXTERN_C void Video_DisableOverlay(int layer);
EXTERN_C void Video_Render();
EXTERN_C void Video_AutoRender();
EXTERN_C void Video_SetTransLevel(Byte level);
EXTERN_C Boolean Video_InitVideo();


// for power management
typedef struct {
    BufferCopyFunc PowerOffCopy;
    BufferCopyFunc DarkenCopy;
    BufferCopyFunc NormalCopy;
}BufferCopy;
#define Color32To16(color32) (WORD)((((color32) & 0xF80000) >> 8) | \
                                (((color32) & 0x00FC00) >> 5) | \
                                (((color32) & 0x0000F8) >> 3))
#define Color16To32(color16) (WORD)((((color16) & 0xF800) << 8) | \
                                (((color16) & 0x7E0) << 5) | \
                                (((color16) & 0x1F) << 3))

#endif // __FRAMEBUFFER_H__
